package com.hj.aiagent.rag;

import lombok.extern.slf4j.Slf4j;
import org.springframework.ai.chat.client.advisor.RetrievalAugmentationAdvisor;
import org.springframework.ai.chat.client.advisor.api.Advisor;
import org.springframework.ai.rag.retrieval.search.VectorStoreDocumentRetriever;
import org.springframework.ai.vectorstore.VectorStore;
import org.springframework.ai.vectorstore.filter.Filter;
import org.springframework.ai.vectorstore.filter.FilterExpressionBuilder;

/**
 * @author: hj
 * @description: 创建自定义的 RAG 检索增强顾问的工厂
 * @date: 2025/7/4 9:21
 */
@Slf4j
public class LoveAppRagCustomAdvisorFactory {
    public static Advisor createLoveAppRagCustomAdvisor(VectorStore vectorStore, String status) {
        // 过滤特定状态的文档
        Filter.Expression expression = new FilterExpressionBuilder().eq("status", status).build();

        //创建文档检索器
        VectorStoreDocumentRetriever documentRetriever = VectorStoreDocumentRetriever.builder().vectorStore(vectorStore).filterExpression(expression).similarityThreshold(0.5).topK(3).build();

        return RetrievalAugmentationAdvisor.builder().documentRetriever(documentRetriever).queryAugmenter(LoveAppContextualQueryAugmenterFactory.createInstance()).build();
    }
}
